<?php

namespace Modules\Order\Http\Controllers\Client\V1;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use Modules\Order\Entities\BaseOrder as Order;

use Modules\Asset\Entities\PackageSku;

use Validator;
use ThrowException;
use Auth;

class OrderStatController extends Controller
{
    public function totalStat(Request $req)
    {
        $rule = [
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest();

        $user = Auth::requireLoginUser();

        $orderType = 'all';

        $stat = [
            'pending_package_sku' => PackageSku::where('user_id', $user->id)->status('pending')->count(),
            'pending' => Order::status('pending')->user($user)->type($orderType)->displayAtClient()->count(),
            'deliver_pending' => Order::status('deliver_pending')->user($user)->type($orderType)->displayAtClient()->count(),
            'pay_pending' => Order::status('pay_pending')->user($user)->type($orderType)->displayAtClient()->visible()->count(),
            'delivered' => Order::status('delivered')->user($user)->type($orderType)->displayAtClient()->count(),
            'all' => Order::type($orderType)->user($user)->displayAtClient()->count()
        ];

        // for test
        // $stat = [
        //     'pending' => 12,
        //     'deliver_pending' => 2,
        //     'pay_pending' => 3,
        //     'delivered' => 9,
        // ];

        return [
            'info' => $stat
        ];
    }
}
